<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>部门管理</title>
    <link rel="stylesheet" href="/ercms/lib/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/ercms/lib/bootstrap-icons/font/bootstrap-icons.css">
    <link rel="stylesheet" href="/ercms/css/main.css">
    <th:block th:replace="~{fragments/header :: navbarStyles}"></th:block>
    
    <!-- 引入认证管理脚本 -->
    <script th:src="@{/js/auth.js}"></script>

    <style>
        .department-tree {
            max-height: 600px;
            overflow-y: auto;
        }
        .department-item {
            cursor: pointer;
            padding: 8px;
            border-radius: 4px;
            margin: 2px 0;
        }
        .department-item:hover {
            background-color: #f8f9fa;
        }
        .department-item.selected {
            background-color: #e3f2fd;
        }
        .department-children {
            margin-left: 20px;
        }
        .department-icon {
            margin-right: 8px;
        }
        .btn-group-sm .btn {
            padding: 0.25rem 0.5rem;
            font-size: 0.875rem;
        }
    </style>
</head>
<body>
    <div th:replace="~{fragments/header :: navbar}"></div>
    <div class="container-fluid mt-3">
        <div class="row">
            <div class="col-md-4">
                <div class="card">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <h5 class="mb-0">部门结构</h5>
                        <button class="btn btn-primary btn-sm" onclick="showCreateDepartmentModal()">
                            <i class="bi bi-plus"></i> 新建部门
                        </button>
                    </div>
                    <div class="card-body">
                        <div id="departmentTree" class="department-tree"></div>
                    </div>
                </div>
            </div>
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0">部门详情</h5>
                    </div>
                    <div class="card-body" id="departmentDetails">
                        <div class="text-center text-muted">
                            <i class="bi bi-building" style="font-size: 3rem;"></i>
                            <p class="mt-2">请选择一个部门查看详情</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 创建/编辑部门模态框 -->
    <div class="modal fade" id="departmentModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="modalTitle">创建部门</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <form id="departmentForm">
                        <div class="mb-3">
                            <label for="departmentName" class="form-label">部门名称 *</label>
                            <input type="text" class="form-control" id="departmentName" required>
                        </div>
                        <div class="mb-3">
                            <label for="departmentDescription" class="form-label">部门描述</label>
                            <textarea class="form-control" id="departmentDescription" rows="3"></textarea>
                        </div>
                        <div class="mb-3">
                            <label for="parentDepartment" class="form-label">上级部门</label>
                            <select class="form-control" id="parentDepartment">
                                <option value="">无（顶级部门）</option>
                            </select>
                        </div>
                        <div class="mb-3">
                            <label for="departmentManager" class="form-label">部门管理员</label>
                            <select class="form-control" id="departmentManager">
                                <option value="">请选择管理员</option>
                            </select>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="saveDepartment()">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 设置管理员模态框 -->
    <div class="modal fade" id="managerModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">设置部门管理员</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <div class="mb-3">
                        <label for="newManager" class="form-label">选择管理员</label>
                        <select class="form-control" id="newManager">
                            <option value="">请选择管理员</option>
                        </select>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="setManager()">确定</button>
                </div>
            </div>
        </div>
    </div>

    <script src="/ercms/lib/bootstrap/js/bootstrap.bundle.min.js"></script>
      <script th:src="@{/js/navbar.js}"></script>
    <script th:src="@{/js/department.js}"></script>
    <script th:src="@{/js/permission.js}"></script>
</body>
</html> 
